package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.CustomerLost;
import cn.wolfcode.crm.page.PageResult;
import cn.wolfcode.crm.query.CustomerLostQueryObject;
import cn.wolfcode.crm.service.ICustomerLostService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("customerLost")
public class CustomerLostController {

    @Autowired
    private ICustomerLostService customerLostService;

    @RequestMapping("")
    @RequiresPermissions("customerLost:index")
    @PermissionName("客户流失记录")
    public String index() {
        return "customer_lost";
    }


    @RequestMapping("list")
    @ResponseBody
    public PageResult list(CustomerLostQueryObject qo) {

        PageResult result = customerLostService.query(qo);

        return result;
    }

    @RequestMapping("lost")
    @RequiresPermissions("customerLost:lost")
    @PermissionName("客户流失记录保存")
    @ResponseBody
    public JsonResult lost(CustomerLost customerLost) {
        JsonResult result = new JsonResult();
        try{
            customerLostService.lost(customerLost);
            result.setMessage("记录保存成功");
        }catch (Exception e){
            e.printStackTrace();
            result.mark("保存失败");
        }

        return result;
    }

}